<template>

  <a-spin :tip="'正在导出,请等待...'" size="large" :spinning="loading" style="font-size: 18px">

  <div class="content">
    <div style="display: flex;justify-content: left;margin-left:30px;align-items: center">
      <a-button v-if="isHome" @click="openNewFolder"  style="margin-right: 10px" type="primary" title='新建文件夹'>
        <span class="icon iconfont">&#xe69a;</span>
      </a-button>
      <a-button v-show="isHome" class='export' type="primary" title='导出' @click="showExport">
        <span class='icon iconfont'>&#xe6bf;</span>
      </a-button>
    </div>
    <v-contextmenu ref="contextmenuf">
      <v-contextmenu-item @click="delfolder(seltedItem)"><span class='icon iconfont'>&#xe6c0;</span> 删除</v-contextmenu-item>
    </v-contextmenu>
    <div v-if="isHome" class="folderListBox">
      <div
        class="folderBox"
        v-for="(item, index) in list"
        :key="index"
        :id="index"
        @contextmenu.prevent="rightClick(item)"
        v-contextmenu:contextmenuf
      >
          <img src="@/assets/closefile.png" alt="" @click="eventAgent(item)">
          <p :title="item.name">{{ item.name }}</p>
          <!--          <span v-if="item.fileList.length != 0" class="folderNum">{{ item.fileList.length }}</span>-->
      </div>

    </div>

    <div v-else class="fileListBox" style="margin-top: 20px">
      <div style="display: flex; justify-content: left">
        <a-button class="btn" @click="backHome()" style="margin-left: 60px" type="primary" title='返回'>
          <span class='icon iconfont'>&#xe68f;</span>
        </a-button>
        <a-upload
          style="margin-left: 10px"
          :multiple="true"
          :file-list="fileList"
          :customRequest="customUpload"
          :before-upload="beforeFileUpload"
          :showUploadList="false"
          class="uploadBox"
          accept=".doc,.docx,.xls,.xlsx,.xps,.jpg,.jpeg,.png,.pdf,.txt,.ppt,.pptx,.zip,.rar,.avi,.mov,.mp4,.rm,.rmvb,.webm,.mp3,.wav,.wma,.midi,.aac"
        >
          <a-button class="abtn" title='上传' type="primary">
            <span class='icon iconfont'>&#xe677;</span>
          </a-button>
          <a-tooltip>
            <template slot="title">
              仅支持上传doc、docx、xls、xlsx、xps、jpg、jpeg、png、pdf、txt、ppt、pptx、zip、rar、avi、mov、mp4、rm、rmvb、webm、mp3、wav、wma、midi、aac格式的文件。
            </template>
            <a-icon type="question-circle" style="margin-left: 8px;color: orange;" />
          </a-tooltip>
        </a-upload>
        <div><span style="line-height: 38px;margin-left: 10px; font-size: 18px; font-weight: bold;">当前位置: {{ fpos }}</span></div>
      </div>
      <div class="file_content" style="padding: 20px; margin-top: 20px;height: 800px">
        <div v-if="file.length > 0" style="display: flex;flex-wrap: wrap;">
          <div
            class="fileBox"
            v-for="(item, index) in file"
            :key="index"
            :id="index"
            @contextmenu.prevent="rightClick(item)"
            v-contextmenu:contextmenu
            @click="eventFlie(item)">
<!--            <a-popconfirm
              title="是否确认要删除当前文件?"
              ok-text="确认"
              cancel-text="取消"
              @confirm="delfile(item.fid,item.documentsType)"
            >
              <img src="@/assets/del.png"
                   class="del" />
            </a-popconfirm>-->
            <!-- @contextmenu.prevent.stop="rightClick($event, item)" -->
            <a-tooltip placement="top">
              <template #title>
                <span>{{ item.fileName }}</span>
              </template>

              <img v-if="item.fileType == 'xls'" src="@/assets/icon/excel.png" class="img_box" />
              <img v-if="item.fileType == 'xlsx'" src="@/assets/icon/excel.png" class="img_box" />
              <img v-if="item.fileType == 'doc'" src="@/assets/icon/word.png" class="img_box" />
              <img v-if="item.fileType == 'docx'" src="@/assets/icon/word.png" class="img_box" />
              <img v-if="item.fileType == 'xps'" src="@/assets/icon/word.png" class="img_box" />
              <img v-if="item.fileType == 'ppt'" src="@/assets/icon/ppt.png" class="img_box" />
              <img v-if="item.fileType == 'pptx'" src="@/assets/icon/ppt.png" class="img_box" />
              <img v-if="item.fileType == 'pdf'" src="@/assets/icon/PDF.png" class="img_box" />
              <img v-if="item.fileType == 'gif'" src="@/assets/icon/GIF.png" class="img_box" />
              <img v-if="item.fileType == 'txt'" src="@/assets/icon/TXT.png" class="img_box" />
              <img v-if="item.fileType == 'jpg'" src="@/assets/icon/IMG.png" class="img_box" />
              <img v-if="item.fileType == 'png'" src="@/assets/icon/IMG.png" class="img_box" />
              <img v-if="item.fileType == 'jpeg'" src="@/assets/icon/IMG.png" class="img_box" />
              <img v-if="item.fileType == 'icon'" src="@/assets/icon/IMG.png" class="img_box" />
              <img v-if="item.fileType == 'zip'" src="@/assets/icon/zip.png" class="img_box" />
              <img v-if="item.fileType == 'rar'" src="@/assets/icon/zip.png" class="img_box" />
              <img v-if="item.fileType == 'avi'" src="@/assets/icon/video.png" class="img_box" />
              <img v-if="item.fileType == 'mov'" src="@/assets/icon/video.png" class="img_box" />
              <img v-if="item.fileType == 'mp4'" src="@/assets/icon/video.png" class="img_box" />
              <img v-if="item.fileType == 'rm'" src="@/assets/icon/video.png" class="img_box" />
              <img v-if="item.fileType == 'rmvb'" src="@/assets/icon/video.png" class="img_box" />
              <img v-if="item.fileType == 'webm'" src="@/assets/icon/video.png" class="img_box" />
              <img v-if="item.fileType == 'mp3'" src="@/assets/icon/audio.png" class="img_box" />
              <img v-if="item.fileType == 'wav'" src="@/assets/icon/audio.png" class="img_box" />
              <img v-if="item.fileType == 'wma'" src="@/assets/icon/audio.png" class="img_box" />
              <img v-if="item.fileType == 'midi'" src="@/assets/icon/audio.png" class="img_box" />
              <img v-if="item.fileType == 'aac'" src="@/assets/icon/audio.png" class="img_box" />

              <!--                <a-badge :count="getDatafileLength(item)" v-if="item.fileType == 'folder'" :offset="offset" :overflowCount="99" :number-style="{ backgroundColor: '#f04f79' }">-->
              <!--              <img v-if="item.fileType == 'folder'" src="@/assets/closefile.png"  style="width: 80px;height: 60px;" @click="nexteventAgent(item)"/>-->
              <!--                </a-badge>-->

              <!--              <svg-->
              <!--                class="icon svg-icon"-->
              <!--                aria-hidden="true"-->
              <!--                style="width: 60px;height: 60px;"-->
              <!--                v-if="item.fileType == 'txt' || item.fileType == 'jpg' || item.fileType == 'png' || item.fileType == 'pdf' || item.fileType == 'zip' || item.fileType == 'jpeg'"-->
              <!--              >-->
              <!--                <use v-if="item.fileType === 'txt'" :xlink:href="getIcon(item.fileType)"></use>-->
              <!--                <use v-if="item.fileType === 'jpg'" :xlink:href="getIcon(item.fileType)"></use>-->
              <!--                <use v-if="item.fileType === 'jpeg'" :xlink:href="getIcon(item.fileType)"></use>-->
              <!--                <use v-if="item.fileType === 'png'" :xlink:href="getIcon(item.fileType)"></use>-->
              <!--                <use v-if="item.fileType === 'pdf'" :xlink:href="getIcon(item.fileType)"></use>-->
              <!--                <use v-if="item.fileType === 'zip'" :xlink:href="getIcon(item.fileType)"></use>-->
              <!--              </svg>-->
            </a-tooltip>
            <p :title="item.fileName" class="text">{{ item.fileName }}</p>
          </div>
        </div>
        <div v-else style="margin: 12% auto 30px auto;">
          <a-empty />
        </div>
        <v-contextmenu ref="contextmenu">
          <v-contextmenu-item @click="delfile(seltedItem.fid,seltedItem.documentsType)"><span class='icon iconfont'>&#xe6c0;</span> 删除</v-contextmenu-item>
          <v-contextmenu-item @click="openMove(seltedItem)"><span class='icon iconfont'>&#xe614;</span> 移动</v-contextmenu-item>
          <v-contextmenu-item @click="openInfo(seltedItem)"><span class='icon iconfont'>&#xe6a2;</span> 详细信息</v-contextmenu-item>
        </v-contextmenu>
      </div>
      <!-- <v-contextmenu ref="contextmenu">
          <v-contextmenu-item @click="download">下载</v-contextmenu-item>
          <v-contextmenu-item @click="preview">预览</v-contextmenu-item>
      </v-contextmenu> -->
    </div>
    <!--
        新建文件夹对话框
     -->
    <a-modal
      centered
      v-model:visible="newlfoldervisible" title="新建文件夹" okText="创建" @ok="saveFolder" @cancel="handleCancel">
      <a-form-model
        ref="formState"
        :model="formState"
        :label-col="labelCol"
        :wrapper-col="wrapperCol"
        :rules="rules"
        :key="ModelKey"
      >
        <a-form-model-item label=""  >
        </a-form-model-item>
        <a-form-model-item label="文件夹名称" prop="foldername" >
          <a-input v-model="formState.foldername" />
        </a-form-model-item>
      </a-form-model>
      <template slot="footer">
        <a-button @click="saveFolder" type="primary"  >创建</a-button>
        <a-button @click="handleCancel" >取消</a-button>
      </template>
    </a-modal>
    <a-spin v-show="false" />

    <a-modal v-model:visible="exvisible" title="单位名称" @ok="handleOk" centered >

      <a-form ref="upform" :key="nkey">
        <a-form-item :aria-colspan="18">
          <a-input v-model.trim="unitname" placeholder="输入单位名称" style="margin-top: 20px ; border: none;"></a-input>
        </a-form-item>
      </a-form>
      <template slot="footer">
        <a-button @click="handleOk" type="primary"  >确定</a-button>
        <a-button @click="handleCancelex" >取消</a-button>
      </template>


    </a-modal>
    <a-modal v-model:visible="infoshow" title="文件详情" @ok="handleOk" centered >
      <a-form :key="nkey"  :label-col="{ span: 6 }"
              :wrapper-col="{ span: 18 }">
        <a-form-item  label="路径">
          <span>/{{ fpos }}</span>
        </a-form-item>
        <a-form-item  label="文件名称">
          <span>{{ seltedItem.fileName }}</span>
        </a-form-item>
        <a-form-item  label="文件大小">
          <span>{{ getFileSize(seltedItem.size) }}</span>
        </a-form-item>
        <a-form-item  label="创建时间">
          <span>{{ seltedItem.uploadTime }}</span>
        </a-form-item>
      </a-form>
      <template slot="footer">
        <a-button @click="handleCanceinfo" >取消</a-button>
      </template>
    </a-modal>

    <a-modal v-model:visible="movevisible" title="选择文件夹" @ok="handleOk" centered :height="600" @cancel="handleCanceMove">
      <div class='tree-box'>
        <a-input-search  placeholder='请输入关键字搜索' @change='onChange' class="ms" v-model="svalue"/>
        <a-tree v-if='treeData.length > 0'    :show-line='false'
                show-icon  :tree-data='treeData' @check='onCheck'
                :replace-fields='replaceFields' :multiple='false' :checkStrictly='false'
                :defaultExpandAll='true'
                :icon='getTreeIcon'
                @select="onSelects"
        >
          </a-tree>
      </div>
      <template slot="footer">
        <a-button @click="handleMoveOk" type="primary"  >确定</a-button>
        <a-button @click="handleCanceMove" >取消</a-button>
      </template>
    </a-modal>

  </div>
  </a-spin>
</template>

<script>
import {} from '@/assets/icon-font/font-lanjian/iconfont.js'; // 注意路径
import '@/assets/icon-font/font-lanjian/iconfont.css';
import {
  uploadAccessToMaterials,
  addAccessToMaterials,
  getAccessToMaterials,
  getAccessFileDir,
  delAccessToMaterials,
  exportDYZLAlls,
  streamToBuffer,
  makeFolder,
  exportDYZLAllsv2,
  getUnitName,
  setUnitName,
  makeFolder2,
  delFolder2,
  getFileSize,
  moveFile2,
  exportDYZLAllsvV2,
} from '@/utils/JsonTools';
import { forEach } from 'core-js/stable/dom-collections';
import fs from 'fs';
import { conver2 } from '@/utils/Code2Code';
import {getAppLocalPath, getNowMilliSecond} from '@/utils/common';

import  wjj from '@/assets/wjj.png'
export default {
  name: 'fileList',
  data() {
    return {
      svalue:"",
      replaceFields: {
        title: 'label',
        key: 'id',
      },
      keyWorld: '',
      treeData: [],
      checkedKeys: [],
      selectFolder:[],
      movevisible:false,
      infoshow:false,
      seltedItem:{},
      loading:false,
      nkey: getNowMilliSecond(),
      unitname: '',
      exvisible: false,
      offset: [-20, 50],
      ModelKey: 1,
      isHome: true,
      list: [],
      folder: {},
      movefolder: {},
      oldfolder: {},
      listInandOutList: [],
      file: [],
      fileList: [],
      currentFile: {},
      newlfoldervisible: false,
      labelCol: { span: 6 },
      wrapperCol: { span: 14 },
      formState: {},
      fpos: '',
      // 表单规则
      rules: {
        foldername: [{ required: true, message: '请输入文件夹名称', trigger: 'blur' }],
      },
      findex: 0,
      percent:0
    };
  },
  created() {
    this.getFiledir();
  },
  mounted() {

  },
  methods: {
    getTreeData(){
      this.treeData=[]
      getAccessFileDir().then(res => {
        if (res != null && res.length > 0) {
          res.forEach(items => {
            let itemdir = {};
            itemdir.id = items.id_;
            itemdir.label = items.f_directory_name_;
            this.treeData.push(itemdir);
          });
        }
      });
    },
    onCheck(checkedKeys) {
      this.checkedKeys = checkedKeys || [];
      console.log("chc--",this.checkedKeys)
    },
    onSelects(e) {
      console.log("chc--",e)
      this.selectFolder=e
    },
    onChange(e) {
      this.selectFolder=undefined
      this.keyWord = e.target.value;
      let alldata=[]
      getAccessFileDir().then(res => {
        if (res != null && res.length > 0) {
          res.forEach(items => {
            let itemdir = {};
            itemdir.id = items.id_;
            itemdir.label = items.f_directory_name_;
            alldata.push(itemdir);
          });

          if(this.keyWord===""){
            this.treeData=alldata
            console.log("ww1--",this.keyWord.replace(" ",""))
          }else{
            console.log("ww--",this.keyWord.replace(" ",""))
            const data=this.treeData.filter(item=>{
              return item.label.indexOf(this.keyWord)>-1
            })
            this.treeData=data
          }
        }
      });
      },
    getFileSize,
    clickOutside() {
      this.operateShow = false
    },
    rightClick(item){
      this.seltedItem = item
    },
    getNowMilliSecond,
    showExport() {
      this.exvisible = true;
      this.nkey = getNowMilliSecond();
      //this.unitname = undefined;
      this.unitname=getUnitName()
      console.log("uname----",this.unitname)

    },
    handleOk() {
      if (this.unitname == undefined || this.unitname == '') {
        this.$message.warn('请输入单位名称');
        return;
      }

      this.exportDYZLAll();
    },
    openNewFolder() {
      this.$nextTick(() => {
        this.ModelKey = this.getModelKey();
      });
      this.newlfoldervisible = true;
    },
    delfolder(item){
      console.log("frm---",item)
      delFolder2(item).then(res=>{
        if(res.status===0){
          this.$message.error("删除失败")
          return
        }
        if(res.status===2){
          this.$message.warn("内置文件夹，无法删除")
          return
        }
        this.$message.success("删除成功")
        this.getFiledir()
      })
    },
    saveFolder(e) {
      this.$refs.formState.validate(valid => {
        if (valid) {
          this.folder.foldername = this.formState.foldername;
          makeFolder2(this.folder).then(res => {
            if (res.status == 0) {
              this.$message.error('创建失败');
              return;
            }
            if (res.status == 2) {
              this.$message.warn('创建失败,文件夹已存在');
              return;
            }
            this.$message.success('创建成功');
            this.newlfoldervisible=false
            this.getFiledir()
            this.formState.foldername=""
            // this.file.push(res);
            // this.folder.fileList.push(res);
            // //升序排序
            // this.file.sort((a, b) => {
            //   let atime = this.formatDate(new Date(a.uploadTime), 'Y-M-D h:m:s');
            //   let btime = this.formatDate(new Date(b.uploadTime), 'Y-M-D h:m:s');
            //   if (atime < btime) {
            //     return 1;
            //   } else if (atime > btime) {
            //     return -1;
            //   } else {
            //     if (atime < btime) {
            //       return -1;
            //     } else if (atime > btime) {
            //       return 1;
            //     }
            //     return 0;
            //   }
            // });
            // //升序排序
            // this.folder.fileList.sort((a, b) => {
            //   let atime = this.formatDate(new Date(a.uploadTime), 'Y-M-D h:m:s');
            //   let btime = this.formatDate(new Date(b.uploadTime), 'Y-M-D h:m:s');
            //   if (atime < btime) {
            //     return 1;
            //   } else if (atime > btime) {
            //     return -1;
            //   } else {
            //     if (atime < btime) {
            //       return -1;
            //     } else if (atime > btime) {
            //       return 1;
            //     }
            //     return 0;
            //   }
            // });
            // this.newlfoldervisible = false;
            // this.$message.success('创建成功');
            // this.formState.foldername = '';
            // this.$refs.formState.foldername = '';
          });
        }
      });

    },
    formatDate(value, format) {
      const formatNumber = n => `0${n}`.slice(-2);
      const date = value;
      const formatList = ['Y', 'M', 'D', 'h', 'm', 's'];
      const resultList = [];
      resultList.push(date.getFullYear().toString());
      resultList.push(formatNumber(date.getMonth() + 1));
      resultList.push(formatNumber(date.getDate()));
      resultList.push(formatNumber(date.getHours()));
      resultList.push(formatNumber(date.getMinutes()));
      resultList.push(formatNumber(date.getSeconds()));
      for (let i = 0; i < resultList.length; i++) {
        format = format.replace(formatList[i], resultList[i]);
      }
      return format;
    },
    handleCancel(e) {
      this.newlfoldervisible = false;
    },
    handleCancelex(e) {
      this.exvisible = false;
    },
    handleCanceinfo(e){
      this.infoshow=false
    },
    handleCanceMove(e){
      this.movevisible=false
      this.svalue=""
    },
    handleMoveOk(e){

      if(this.treeData.length===0){
        this.$message.warn('文件夹不存在');
        return;
      }
      if(this.selectFolder===undefined) {
        this.$message.warn('请选择文件夹!');
        return;
      }
      if(!this.selectFolder.length===0) {
        this.$message.warn('请选择文件夹!');
        return;
      }
      console.log("fp--1--",this.fpos)
      const listmos=this.list.filter(is=>{
        return this.selectFolder[0]===is.id
      })
      console.log("fp--2--",this.list)
      if(listmos[0].name===this.fpos){
        this.$message.warn("已在当前文件夹，请选择其他文件夹")
        return;
      }
      this.moveFile()
    },
    getModelKey() {
      return (Math.random() * 100000000);
    },
    moveFile(){
      moveFile2(this.seltedItem,this.selectFolder).then(res=>{
          if(res===0){
            this.$message.error("移动失败，请重试")
            return
          }
        if(res===2){
          this.$message.warn("文件已存在，请重命名")
          return
        }
            const sxl=this.file.filter(its=>{
              return its.id!=this.seltedItem.id
            })
           console.log("sxl---",sxl)
           this.file=sxl
            this.$message.success("移动成功")
            this.movevisible=false
            this.seltedItem={}
            this.selectFolder=undefined
      })
    },
    openInfo(item){
      this.infoshow=true
      console.log("its--",item)
    },
    openMove(item){
      this.movevisible=true
      console.log("its--",item)
      this.getTreeData()
    },
    delfile(id, dirid) {
      delAccessToMaterials(id, dirid).then(res => {
        // eslint-disable-next-line eqeqeq
        if (res == 0) {
          this.$message.error('删除失败');
          return;
        }
        // this.fileList = []
        //  this.list = []
        // this.file = []
        // this.$nextTick(s => {
        //   this.list.forEach(itemdir => {
        //     console.log('id---'+ itemdir.fileList.length)
        this.file.forEach(item => {
          // eslint-disable-next-line no-cond-assign,eqeqeq
          if (item.fid === id && item.documentsType === dirid) {
            let index = this.file.indexOf(item);
            if (index > -1) {
              this.file.splice(index, 1);
            }
          }
        });
        this.folder.fileList.forEach(item => {
          // eslint-disable-next-line no-cond-assign,eqeqeq
          if (item.fid === id && item.documentsType === dirid) {
            let index = this.folder.fileList.indexOf(item);
            if (index > -1) {
              this.folder.fileList.splice(index, 1);
            }
          }
        });
        this.list.forEach(item2 => {
          // eslint-disable-next-line no-cond-assign,eqeqeq
          // item.fileList.forEach(item2 => {
          // eslint-disable-next-line no-cond-assign,eqeqeq
          if (item2.fid === id && item2.documentsType === dirid) {
            let index = this.list.fileList.indexOf(item2);
            if (index > -1) {
              this.list.fileList.splice(index, 1);
            }
          }
          // })
        });
      });
    },
    getFiledir() {
      this.list=[]
      getAccessFileDir().then(res => {
        if (res != null && res.length > 0) {
          res.forEach(items => {
            let itemdir = {};
            itemdir.id = items.id_;
            itemdir.name = items.f_directory_name_;
            itemdir.mtype = this.getfileDirType(items.f_directory_type);
            itemdir.pname = items.f_patrol_object_name_;
            itemdir.fileList = [];
            // eslint-disable-next-line no-undef
            this.list.push(itemdir);
          });
          getAccessToMaterials().then(res => {
            //升序排序
            res.sort((a, b) => {
              let atime = this.formatDate(new Date(a.uploadTime), 'Y-M-D h:m:s');
              let btime = this.formatDate(new Date(b.uploadTime), 'Y-M-D h:m:s');
              if (atime < btime) {
                return 1;
              } else if (atime > btime) {
                return -1;
              } else {
                if (atime < btime) {
                  return -1;
                } else if (atime > btime) {
                  return 1;
                }
                return 0;
              }
            });
            res.forEach(element => {
              this.list.forEach(e => {
                // eslint-disable-next-line eqeqeq
                if (element.documentsType == e.id) {
                  e.fileList.push(element);
                }
              });
            });
          });
        }
      });
    },
    getTreeIcon(props) {
      const { expanded, slots } = props
      let parentId = props['parent_id_']
      let icon = ''
      if (props.children?.length > 0) {
        icon = <img src={wjj} />
      } else {
          icon = <img src={wjj} />
      }
      return icon
      // return <lanjian-icon type={icon} width="20px"></lanjian-icon>
    },
    getIcon(fileType) {
      let icon;
      // eslint-disable-next-line eqeqeq
      if (fileType == 'txt') {
        icon = '#icon-txt';
        // eslint-disable-next-line eqeqeq
      } else if (fileType === 'doc' || fileType == 'docx') {
        icon = '#icon-doc';
        // eslint-disable-next-line eqeqeq
      } else if (fileType === 'docx' || fileType == 'docx') {
        icon = '#icon-doc';
        // eslint-disable-next-line eqeqeq
      } else if (fileType == 'xls' || fileType == 'xlsx') {
        icon = '#icon-excel';
        // eslint-disable-next-line eqeqeq
      } else if (fileType == 'xlsx' || fileType == 'xlsx') {
        icon = '#icon-excel';
        // eslint-disable-next-line eqeqeq
      } else if (fileType == 'jpg' || fileType == 'jpeg') {
        icon = '#icon-jpg';
        // eslint-disable-next-line eqeqeq
      } else if (fileType == 'png') {
        icon = '#icon-png';
      } else if (fileType === 'pdf') {
        icon = '#icon-pdf';
      } else if (fileType === 'ppt') {
        icon = '#icon-ppt';
      } else if (fileType === 'zip') {
        icon = '#icon-zip';
      } else if (fileType === 'pptx') {
        icon = '#icon-ppt';
      }
      return icon;
    },
    eventAgent(e) {
      console.log(e);
      this.isHome = false;
      this.folder = e;
      this.file = [...e.fileList];
      //this.listInandOutList.push(e.name)
      this.fpos = e.name;
    },
    nexteventAgent(e) {
      console.log(e);
      // console.log(this.folder)
      // if(!this.listInandOutList.indexOf(this.oldfolder)>=-1){
      this.findex = this.findex + 1;
      this.listInandOutList.push(e.fileName);
      this.oldfolder = this.folder;
      this.folder = e;
      this.fpos = e.fileName;
      e.fileList = [];
      // }
      getAccessToMaterials().then(res => {
        //升序排序
        res.sort((a, b) => {
          let atime = this.formatDate(new Date(a.uploadTime), 'Y-M-D h:m:s');
          let btime = this.formatDate(new Date(b.uploadTime), 'Y-M-D h:m:s');
          if (atime < btime) {
            return 1;
          } else if (atime > btime) {
            return -1;
          } else {
            if (atime < btime) {
              return -1;
            } else if (atime > btime) {
              return 1;
            }
            return 0;
          }
        });
        res.forEach(item => {
          // eslint-disable-next-line eqeqeq
          if (item.documentsType == e.id) {
            e.fileList.push(item);
          }
        });
        this.file = [...e.fileList];
      });
    },
    proeventAgent(e) {
      console.log(e);
      this.findex = this.findex - 1;
      this.isHome = false;
      this.folder = this.oldfolder;
      this.fpos = this.folder.fileName;
      e.fileList = [];
      getAccessToMaterials().then(res => {
        //升序排序
        res.sort((a, b) => {
          let atime = this.formatDate(new Date(a.uploadTime), 'Y-M-D h:m:s');
          let btime = this.formatDate(new Date(b.uploadTime), 'Y-M-D h:m:s');
          if (atime < btime) {
            return 1;
          } else if (atime > btime) {
            return -1;
          } else {
            if (atime < btime) {
              return -1;
            } else if (atime > btime) {
              return 1;
            }
            return 0;
          }
        });
        res.forEach(item => {
          //console.log(item)
          // eslint-disable-next-line eqeqeq
          if (item.documentsType == e.documentsType) {
            e.fileList.push(item);
          }
        });
        this.file = [...e.fileList];
      });
    },
    getDatafileLength(e) {
      console.log(e);
      let length = 0;
      let data = fs.readFileSync(getAppLocalPath()+'dbson/AccessToMaterials.dbson', 'utf8');
      let res = JSON.parse(data);
      //升序排序
      res.sort((a, b) => {
        let atime = this.formatDate(new Date(a.uploadTime), 'Y-M-D h:m:s');
        let btime = this.formatDate(new Date(b.uploadTime), 'Y-M-D h:m:s');
        if (atime < btime) {
          return 1;
        } else if (atime > btime) {
          return -1;
        } else {
          if (atime < btime) {
            return -1;
          } else if (atime > btime) {
            return 1;
          }
          return 0;
        }
      });
      res.forEach(item => {
        // eslint-disable-next-line eqeqeq
        if (item.documentsType == e.id) {
          length++;
        }
      });
      console.log('length--' + length);
      return length;
    },
    getTitles(list, index) {
      console.log(list);

      let title = '';
      // let sl = list.slice(0,index)
      list.forEach(item => {
        title += ' 》 ' + item;
        console.log(item);
      });
      return title;
    },
    backHome(e) {
      if (this.findex == 0) {
        this.isHome = true;
        this.findex == 0;
        this.listInandOutList = [];
        this.getFiledir()
      } else {
        this.proeventAgent(this.folder);
      }
    },
    eventFlie(e) {

    },
    // // 右键
    // rightClick(event, e) {
    //   const postition = { top: event.clientY, left: event.clientX };
    //   this.$refs.contextmenu.show(postition);
    //   this.currentFile = { ...e }
    // },
    // 上传验证
    beforeFileUpload(file) {
      if (file.name.substring(0, file.name.indexOf('.')).length > 200) {
        this.$message.error('上传文件名字不得超过200字');
        return false;
      }
      // let isLt2M = file.size / 1024 / 1024;
      // if (isLt2M > 200) {
      //   this.$message.error('只允许上传200M以下的文件');
      //   return false;
      // }
      let fileExt = file.name.slice(file.name.lastIndexOf('.') + 1);
      let fileTypeArr = ['doc','docx','xls','xlsx','xps','jpg','jpeg','png','pdf','txt','ppt','pptx','zip','rar','avi','mov','mp4','rm','rmvb','webm','mp3','wav','wma','midi','aac'];
      if (fileTypeArr.indexOf(fileExt) === -1) {
        this.$message.error('非法的文件类型');
        return false;
      }
      return true;
    },
    customUpload(file) {
      console.log(file);
      file.file.documentsType = this.folder.id;
      uploadAccessToMaterials(file.file).then(res => {
        res.dirname = this.folder.name;
        res.mtype = this.folder.mtype;
        res.pname = this.folder.pname;
        res.size = file.file.size;
        addAccessToMaterials(res).then(res1 => {
          // eslint-disable-next-line eqeqeq
          if (res1 == 0) {
            this.$message.error('上传失败')
            return
          }
          if (res1 == 2) {
            this.$message.warn('文件重复,请重新选择')
            return;
          }
          this.$message.success('上传成功');
          this.file.push(res);
          this.folder.fileList.push(res);
          //升序排序
          this.file.sort((a, b) => {
            let atime = this.formatDate(new Date(a.uploadTime), 'Y-M-D h:m:s');
            let btime = this.formatDate(new Date(b.uploadTime), 'Y-M-D h:m:s');
            if (atime < btime) {
              return 1;
            } else if (atime > btime) {
              return -1;
            } else {
              if (atime < btime) {
                return -1;
              } else if (atime > btime) {
                return 1;
              }
              return 0;
            }
          });
          //升序排序
          this.folder.fileList.sort((a, b) => {
            let atime = this.formatDate(new Date(a.uploadTime), 'Y-M-D h:m:s');
            let btime = this.formatDate(new Date(b.uploadTime), 'Y-M-D h:m:s');
            if (atime < btime) {
              return 1;
            } else if (atime > btime) {
              return -1;
            } else {
              if (atime < btime) {
                return -1;
              } else if (atime > btime) {
                return 1;
              }
              return 0;
            }
          });
        });
      });
    },
    async exportDYZLAll() {
      this.exvisible=false
      this.loading=true
      console.log('this.list',this.list)
      // 导出提报
      // eslint-disable-next-line no-undef
      exportDYZLAllsvV2(this.unitname,this.list).then(res => {
        if(res.code===0){
          this.$message.warning('调阅资料文件应小于2GB!')
          this.loading=false
          return
        }
          setUnitName(this.unitname)
          this.loading=false
          saveAs.saveAs(res.data, res.fname);
        });
    },
    async exportDYZLAll1() {
      this.exvisible=false
      this.loading=true
      // 导出提报
      // eslint-disable-next-line no-undef
      setTimeout(()=> {
         exportDYZLAllsv2(this.unitname).then(res => {
          this.loading=false
          // eslint-disable-next-line eqeqeq
          if (res.status == 0) {
            this.$message.error('导出失败');
          } else {
            console.log(res);
            this.$message.success('保存成功');
            setUnitName(this.unitname)
            this.exvisible = false;
            //conver2(res.path,"dayede.zip")

            let fileb = fs.createReadStream(res.path);
            let fsname = res.fname;
            streamToBuffer(fileb).then(res2 => {
              let data = res2;
              console.log('fsname-----' + data.length);
              let contents = new Uint8Array(data.length);
              for (let i = 0; i < data.length; i++) {
                contents[i] = data[i];
              }
              // eslint-disable-next-line no-undef
              saveAs.saveAs(new Blob([contents], { type: 'application/zip' }), fsname);
            });
          }
        });
      }, 2000 );
    },
    getfileDirType(typestr) {
      let t = 0;
      if (typestr === 'materialBefore') {
        t = 1;
      }
      if (typestr === 'materialCurrent') {
        t = 2;
      }
      if (typestr === 'provisionOfMaterials') {
        t = 3;
      }
      if (typestr === 'registrationOfMatters') {
        t = 4;
      }
      // eslint-disable-next-line eqeqeq
      if (typestr === 'customCatalog') {
        t = 5;
      }
      // eslint-disable-next-line eqeqeq
      if (typestr === 'loanMaterial') {
        // eslint-disable-next-line no-unused-vars
        t = 6;
      }
      return t;
    },
  },
};
</script>

<style lang="scss" scoped>
.abtn {
  width: 38px;
  height: 38px;
}

.export {
  width: 38px;
  height: 38px;
  margin-top: 10px;
  margin-bottom: 10px;
}

.content {
  height: calc(100% - 42px);
  background-image: linear-gradient(180deg,
    #ffffff 0%,
    #f4f7ff 81%,
    #f4f7ff 100%),
  linear-gradient(
      #ffffff,
      #ffffff);
  background-blend-mode: normal,
  normal;
  box-shadow: 0px 2px 8px 0px rgba(58, 109, 189, 0.3);
  border-radius: 4px;
}

.img_box {
  width: 156px;
}

.text {
  text-align: center;
  font-size: 22px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: PingFangSC-Regular;
  font-weight: normal;
  font-stretch: normal;
  letter-spacing: 0px;
  color: #333333;
}

.del {
  height: 20px;
  width: 20px;
  position: absolute;
  margin-bottom: 0px;
  right: 15px
}

.folderListBox {
  margin-top: 100px;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  position: fixed;
  margin-left: 60px;
  min-width: 1000px;

  .folderBox {
    cursor: pointer;
    position: relative;
    width: 200px;
    height: 210px;

    &:hover {
      background-color: #d4e7ff;
      border-radius: 2px;
    }

    img {
      width: 156px;
      margin-top: 6px;
    }

    p {
      text-align: center;
      font-size: 22px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      font-family: PingFangSC-Regular;
      font-weight: normal;
      font-stretch: normal;
      letter-spacing: 0px;
      color: #333333;
    }

    .folderNum {
      position: absolute;
      display: inline-block;
      width: 42px;
      line-height: 42px;
      background-color: #f04f79;
      border-radius: 29px;
      text-align: center;
      font-size: 20px;
      color: #fff;
      bottom: 120px;
      right: 54px;
    }
  }
}

.fileListBox {
  min-width: 900px;
  width: 100%;
  position: relative;
  margin-left: 0px;
  .fileBox {
    cursor: pointer;
    position: relative;
    width: 10%;
    min-height: 110px;
    min-width: 160px;
    &:hover{
      .del{
        display: inline-block;
      }
    }
    &:not(:hover){
      .del{
        display: none;
      }
    }
  }
}

.file_content {
  overflow: scroll;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
  background-color: #fcfcfc;
}

::-webkit-scrollbar-thumb {
  background-color: #cccccc;
  border-radius: 8px;
}

.file_content:hover ::-webkit-scrollbar-thumb {
  background-color: #fcfcfc;
}

.file_content ::-webkit-scrollbar-thumb {
  background-color: #cccccc;
}
.operate {
  min-width: 80px;
  min-height: 100px;
  background-color: #fff;
  border-radius: 4px;
  z-index: 1;
  // position: fixed;
  position: absolute;
  padding: 10px 0px;
  box-shadow: 0px 2px 8px 0px rgba(58, 109, 189, 0.3);
  font-size: 16px;
}

.operate-item {
  width: 100%;
  height: 25px;
  line-height: 25px;
  padding: 0 10px;
  cursor: pointer;
  &:hover {
    background-color: rgba(215, 215, 215, 1);
  }
}
.tree-box{
  padding: 0 16px;
}
::v-deep .ant-tree-title{
  font-size:18px;
  line-height: 2%;
  vertical-align: middle;
  margin-left: 1%;
}
::v-deep .ant-tree-iconEle{
  width: 22px;
  height:  22px;
  img{
    width: 100%;
    width: 100%;
  }
}
::v-deep .ant-tree{
  margin: 16px 0 !important;
}
.tree-box > .ant-tree {
  height: 500px;
  overflow-y: auto;
  margin: 16px;
}
.ms{

  margin-top:20px;
}
</style>
